This is a draft version of a MISRA C++ 202x rule proposed for public review.
MISRA Rule 10.0.1
Category: Advisory
Analysis Type: Decidable,Single Translation Unit
Amplification
An init-declarator-list or a member-declarator-list should consist of a single init-declarator or
member-declarator respectively.
Structured bindings are permitted by this rule.
Rationale
Where multiple declarators appear in the same declaration [1], the type of an identifier may not meet developer expectations.
Example
int32_t i1; int32_t j1; // Compliant
int32_t i2, * j2; // Non-compliant
int32_t * i3,
& j3 = i2; // Non-compliant
struct point
{
int32_t x, y; // Non-compliant
};
std::map< char, char > map = f();
auto [ loc, inserted ] =
map.insert( make_pair( 'A', 'a' ) ); // Compliant - structured binding
Glossary
[1] Declaration
A declaration introduces the name of an entity into a translation unit (see [basic.def]/1).
An entity may be declared several times. The first declaration of an entity in a translation unit is
called an introduction [2]. All subsequent declarations are called redeclarations [3].
A definition [4] is a declaration, as described in [basic.def]/2.
[2] Introduction
See declaration [1].
[3] Redeclaration
See declaration [1].
[4] Definition
See declaration [1].
Copyright The MISRA Consortium Limited © 2023